using System.ComponentModel.DataAnnotations;
using FytSoa.Common.Enum;
using FytSoa.Domain.Hr;
using FytSoa.Domain.Sys;
using SqlSugar;

namespace FytSoa.Domain.Crm;

/// <summary>
/// 项目-合同管理
/// </summary>
[SugarTable("crm_contract")]
public class CrmContract:Entity
{
    /// <summary>
    /// 合同名称
    /// </summary>
    [Required]
    [StringLength(50)]
    public string Name { get; set; }

    /// <summary>
    /// 合同编号
    /// </summary>
    [Required]
    [StringLength(30)]
    public string Number { get; set; }

    /// <summary>
    /// 项目编号
    /// </summary>
    [Required]
    public long ProjectId { get; set; }
    
    /// <summary>
    /// 项目
    /// </summary>
    [Navigate(NavigateType.OneToOne, nameof(ProjectId))]
    public CrmProject Project { get; set; }

    /// <summary>
    /// 客户管理
    /// </summary>
    [Required]
    public long CustomerId { get; set; }
    
    /// <summary>
    /// 客户信息
    /// </summary>
    [Navigate(NavigateType.OneToOne, nameof(CustomerId))]
    public CrmCustomer Customer { get; set; }

    /// <summary>
    /// 负责人
    /// </summary>
    [Required]
    public long EmployeeId { get; set; }
    
    /// <summary>
    /// 负责人
    /// </summary>
    [Navigate(NavigateType.OneToOne, nameof(EmployeeId))]
    public HrEmployee Employee { get; set; }

    /// <summary>
    /// 签约人
    /// </summary>
    [Required]
    public long SignEmployeeId { get; set; }
    
    /// <summary>
    /// 签约人
    /// </summary>
    [Navigate(NavigateType.OneToOne, nameof(SignEmployeeId))]
    public HrEmployee SignEmployee { get; set; }

    /// <summary>
    /// 金额
    /// </summary>
    [Required]
    public decimal Amount { get; set; }

    /// <summary>
    /// 折扣
    /// </summary>
    [Required]
    public int Discount { get; set; } = 0;

    /// <summary>
    /// 合同类型
    /// </summary>
    [Required]
    public long TypeId { get; set; }
    
    /// <summary>
    /// 合同类型
    /// </summary>
    [Navigate(NavigateType.OneToOne, nameof(TypeId))]
    public SysCode TypeCode { get; set; }

    /// <summary>
    /// 开始时间
    /// </summary>
    [Required]
    public DateTime StartTime { get; set; } = DateTime.Now;

    /// <summary>
    /// 结束时间
    /// </summary>
    [Required]
    public DateTime EndTime { get; set; } = DateTime.Now;

    /// <summary>
    /// 状态=未审核1=审核中2=通过
    /// </summary>
    public CrmAuditEnum Status { get; set; } = CrmAuditEnum.NotReviewed;
    
    /// <summary>
    /// 附件
    /// </summary>
    [SugarColumn(IsJson = true)]
    public List<FileBase> Files { get; set; } = new();

    /// <summary>
    /// 备注
    /// </summary>
    public string Remark { get; set; }

    /// <summary>
    /// 创建人
    /// </summary>
    public string CreateUser { get; set; }

    /// <summary>
    /// 创建时间
    /// </summary>
    [Required]
    public DateTime CreateTime { get; set; } = DateTime.Now;

    /// <summary>
    /// 更新人
    /// </summary>
    public string UpdateUser { get; set; }

    /// <summary>
    /// 更新时间
    /// </summary>
    public DateTime? UpdateTime { get; set; }


}